"use strict";

module.exports = (app) => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const DictItem = app.model.define(
    "dict_item",
    {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      item_text: { type: STRING(100), allowNull: false },
      item_value: { type: STRING(255), allowNull: false },
      item_color: {
        type: STRING(255),
        allowNull: false,
        defaultValue: "#ffffff",
      },
      dict_id: {
        type: INTEGER,
        allowNull: false,
      },
      status: { type: INTEGER, defaultValue: 1 }, // 1: 显示, 0: 隐藏
      description: { type: STRING(255), allowNull: true },
      created_at: DATE,
      updated_at: DATE,
    },
    {
      tableName: "dict_item",
      timestamps: true,
      underscored: true,
      comment: "字典数据表",
      indexes: [{ fields: ["dict_id"] }],
    }
  );

  // 关联字典类型
  DictItem.associate = function () {
    this.belongsTo(app.model.Dict, {
      foreignKey: "dict_id",
      as: "dict",
    });
  };

  return DictItem;
};
